#ifndef MCL_WRITER_H_
#define MCL_WRITER_H_

#include <stdio.h>
#include "mcl/da.h"

enum writertype {
	WRITER_FILE,
	WRITER_BUFFER,
};

struct writer {
	enum writertype type;
	union {
		FILE *fp;
		struct dstr buf;
	} via;
};

struct writer new_writer_from_buffer(void);
struct writer new_writer_from_file(FILE *fp);

void writer_deinit(struct writer *w);

void write_bytes(struct writer *w, char const *start, usize len);

void write_cstr(struct writer *w, char const *s);

void write_pointer(struct writer *w, void *p);

void write_dstr(struct writer *w, struct dstr const *dstr);
void write_dstr_view(struct writer *w, struct dstr_view const *dstr);

void write_bool(struct writer *w, bool b);

void write_i64(struct writer *w, int64_t x);

#endif
